 <?php
 
 if (!isset($_POST['new_category'])) {
            echo "
        <form action='admin.php?action=addcategory' method='post'>
        <table border='0' cellpadding='0' cellspacing='0' width='500'>
            <tr>
                <td>Category name:</td>
                <td><input type='text' name='category' maxlength='25'></td>
            </tr>
            <tr>
                <td>Description:</td>
                <td><textarea name='description' cols='40' rows='10'></textarea></td>
            </tr>
            <tr>
                <td colspan='2'><center><input type='submit' name='new_category' value='New Category!'></td>
            </tr>
        </table>
        </form>
        ";
        }
        //else, error check and then insert data to database!
        elseif (isset($_POST['new_category'])) {
            $category = secure($_POST['category']);
            $description = secure($_POST['description']);

            //begin error reporting
            $error_msg = array();
            if (empty($category)) {
                $error_msg[] = "No Category name entered!<br />";
            }
            if (empty($description)) {
                $error_msg[] = "No description entered!<br />";
            }
            //print errors, if any
            if (count($error_msg) > 0) {
                echo "<strong>ERROR:</strong><br>n";
                foreach ($error_msg as $err)
                    echo "$err";
            }
            //else, no errors, insert to the DB!
            else {
                $query = mysql_query("INSERT INTO page_categories (category, description) VALUES ('$category', '$description')") or
                    die(mysql_error());
                echo "Category Added";
            }
        }
		
		?>